package com.eversec.msg.service.impl;

import com.eversec.kafka.exception.KafkaInitException;
import com.eversec.msg.service.KafkaService;
import com.eversec.msg.util.KafkaUtil;
import org.apache.kafka.clients.producer.Callback;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by eversec on 2018/1/19.
 */
@Service
public class KafkaServiceImpl implements KafkaService {




    @Override
    public void sendKafkaMessages(String topic ,List<String> msgs){

        try {
            KafkaUtil.getKafkaProducerServer().sendMessages(topic, null, msgs);
        } catch (KafkaInitException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void sendKafkaMessage(String topic, String msg) {
        try {
            List<String> message = new ArrayList<>();
            message.add(msg);
            KafkaUtil.getKafkaProducerServer().sendMessages(topic, null, message);
        } catch (KafkaInitException e) {
            e.printStackTrace();
        }
    }
}
